<template>
			<el-form :model="editForm"  label-width="120px" :rules="editFormRules" ref="editFormRef"> 
				<el-form-item label="角色名" prop="rolename">
					<el-input v-model="editForm.rolename" placeholder="角色名" :maxlength="255" @change="editSomeFields(editForm,'rolename',$event)" :disabled="disField"/>
				</el-form-item> 
				<el-form-item label="角色编号" prop="roleid">
					<el-input v-model="editForm.roleid" placeholder="角色编号" :maxlength="50" @change="editSomeFields(editForm,'roleid',$event)" :disabled="disField"/>
				</el-form-item> 
                
				<el-form-item label="是否启用" prop="enabled">
					<mdp-select width="100%" item-code="enabled" v-model="editForm.enabled" placeholder="是否启用" :maxlength="1" @change="editSomeFields(editForm,'enabled',$event)" :disabled="disField"/>
				</el-form-item>   
				<el-form-item label="角色类型" prop="roletype">
                    <el-switch @change="editSomeFields(editForm,'roletype',$event)" :disabled="disField"
					  v-model="editForm.roletype"
					  active-text="公共角色"
					  inactive-text="自定义角色"
					  active-value="1"
					  inactive-value="0"/>
					<div class="label-font-color">公共角色为全平台共享，不区分机构，自定义角色按机构划分，本机构只能查询本机构的角色</div>
 				</el-form-item> 
                
				<el-form-item label="数据访问等级" prop="dataLvl">
					<mdp-select width="100%" item-code="dataLvl" v-model="editForm.dataLvl" :min="0" :max="200" :disabled="disField"/>
				</el-form-item> 
				<el-form-item label="备注" prop="remark">
					<el-input type="texteara" v-model="editForm.remark" placeholder="备注" :maxlength="255" @change="editSomeFields(editForm,'remark',$event)" :disabled="disField"/>
				</el-form-item> 
				 
				<el-form-item label="角色排序" prop="sortOrder">
					<el-input type="number" v-model="editForm.sortOrder" placeholder="角色排序" :disabled="disField" :maxlength="2"/>
				</el-form-item> 
				<el-form-item label="创建日期" prop="crdate" v-if="currOpType!='add'">
					<el-date-picker type="date" placeholder="选择日期" v-model="editForm.crdate"  value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD" :disabled="disField||true"/>
				</el-form-item> 
				<el-form-item label="机构编号" prop="branchId" v-if="currOpType!='add'">
					<el-input v-model="editForm.branchId" placeholder="云用户机构编号" :maxlength="50" @change="editSomeFields(editForm,'branchId',$event)" :disabled="disField||true"/>
				</el-form-item>  
			</el-form>

		<el-row class="footer">
		    <el-button @click="close()">关闭</el-button>
            <el-button v-if="currOpType=='add'" v-loading="load.edit" type="primary" @click="saveSubmit" :disabled="disBtn('addBtn') || !checkBtnQx('addBtn',menuDefId) || load.edit">提交</el-button>
		</el-row> 
</template>

<script>
import util from '@/components/mdp-ui/js/util';//全局公共库
import config from "@/api/mdp_pub/mdp_config"; //全局公共库import
import * as RoleApi from '@/api/mdp/sys/role';
import { mapState } from 'pinia'
import { useUserStore } from '@/store/modules/user'
import { MdpFormMixin } from '@/components/mdp-ui/mixin/MdpFormMixin.js';

export default {
    name:'roleForm',
    mixins:[MdpFormMixin],
    components: {
    },
    computed: {
        ...mapState(useUserStore,['userInfo'])
    },
    props:{
    },
    watch: {
    },
    data() {
        return {
            menuDefId:'',//menu_def.id 菜单表菜单编号，用于按钮权限判断
            pkNames:["roleid"],//表格主键的java属性名称，驼峰命名，默认为id,支持多主键
            
            editFormRules: {
                roleid:[
                //{ required: true, message: '此项必填', trigger: 'change' },
                { min: 1,max: 50, message: '长度在1到50之间', trigger: 'change'}
                ],
                rolename: [
                    { required: true, message: '角色名必输', trigger: 'change' }
                ],
                roletype: [
                    { required: true, message: '角色类型必输', trigger: 'change' }
                ],
                enabled: [
                    { required: true, message: '是否启用必输', trigger: 'change' }
                ],
                sortOrder: [
                    { validator: (rule, value, callback) => {
                        if (!value) {
                            return callback();
                            }
                            if (value > 100) {
                            callback(new Error('数字不能超过100'));
                            } else {
                            callback();
                            }
                        },
                    trigger: 'change'
                    }
                ],
            },
            editForm: {
                roleid:'',rolename:'',remark:'',roletype:'',rolebeg:'',roleend:'',crdate:'',enabled:'',deptid:'',sortOrder:'99',branchId:'',dataLvl:''
            },
            //增删改查(含批量)接口
            apis:{
                queryById: RoleApi.queryRoleById,
                add: RoleApi.addRole,
                edit: RoleApi.editRole,
                editSomeFields: RoleApi.editSomeFieldsRole
            }
        }
    },
    methods: {
        //由组件扩展添加其它的初始页面的逻辑
         initCurrData(){  
            Object.assign(this.editForm,this.formData)
            if(this.currOpType=='add'){ 
                
                this.editForm.branchId=this.userInfo.branchId
                this.editForm.dataLvl='2'
                this.editForm.enabled='1'
                this.editForm.roletype="0"
                this.editForm.sortOrder='99'
            }
         },
        /**
         * 检查参数是否满足调用后台接口的条件
         * @returns true / false
         */
        preParamCheck(params){
            return true;
        },


        /**
         * 对修改的字段进行判断，返回false ,将取消更新数据库,由组件扩展
         * @param {*} row 当前选中的行
         * @param {*} fieldName 修改的字段名
         * @param {*} $event 修改后的值
         * @param {*} params 将要提交服务器的参数
         * @returns true/false 返回false ,将取消更新数据库
         */
        editSomeFieldsCheck(row,fieldName,$event,params){
            params[fieldName]=$event
            return true;
        },
    },
    mounted() {

    }
}

</script>

<style scoped>

</style>